import { pageResultData } from '@/store/storeType'
export const findCat_name = (resData: pageResultData, resultArr: pageResultData[]) => {
  if (resData && resultArr.length !== 0) {
    resultArr.forEach((item: pageResultData) => {
      if (item.cat_id !== resData.cat_id) {
        if (item.children instanceof Array) {
          findCat_name(resData, item.children)
        }
      }
      if (item.cat_id === resData.cat_id) {
        item.cat_name = resData.cat_name
      }
    })
  }
}

export const findNameFn = (resultArr: pageResultData[], cat_id: number, newArr:any = []) : any => {
  resultArr.forEach((item: any) => {
    if (item.cat_id === cat_id) {
      newArr.push(item.cat_name)
    }
    if (item.children && item.children.length > 0) {
      findNameFn(item.children, cat_id, newArr)
    }
  })
  return newArr
}

